﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package org.aswing.ext {
    import org.aswing.*;
    import org.aswing.geom.*;

    public class GridListLayout extends EmptyLayout {

        private var hgap:int;
        private var vgap:int;
        private var rows:int;
        private var cols:int;
        private var tileWidth:int;
        private var tileHeight:int;

        public function GridListLayout(_arg1:int=1, _arg2:int=0, _arg3:int=0, _arg4:int=0){
            if ((((_arg1 == 0)) && ((_arg2 == 0)))){
                throw (new ArgumentError("rows and cols cannot both be zero"));
            };
            this.rows = _arg1;
            this.cols = _arg2;
            this.hgap = _arg3;
            this.vgap = _arg4;
        }
        public function getRows():int{
            return (this.rows);
        }
        public function setRows(_arg1:int):void{
            this.rows = _arg1;
        }
        public function getColumns():int{
            return (this.cols);
        }
        public function setColumns(_arg1:int):void{
            this.cols = _arg1;
        }
        public function getHgap():int{
            return (this.hgap);
        }
        public function setHgap(_arg1:int):void{
            this.hgap = _arg1;
        }
        public function getVgap():int{
            return (this.vgap);
        }
        public function setVgap(_arg1:int):void{
            this.vgap = _arg1;
        }
        public function getTileWidth():int{
            return (this.tileWidth);
        }
        public function getTileHeight():int{
            return (this.tileHeight);
        }
        public function setTileWidth(_arg1:int):void{
            this.tileWidth = _arg1;
        }
        public function setTileHeight(_arg1:int):void{
            this.tileHeight = _arg1;
        }
        override public function preferredLayoutSize(_arg1:Container):IntDimension{
            if ((((this.cols == 0)) && ((this.rows == 0)))){
                throw (new Error("rows and cols cannot both be zero"));
            };
            var _local2:Insets = _arg1.getInsets();
            var _local3:int = _arg1.getComponentCount();
            var _local4:int = this.rows;
            var _local5:int = this.cols;
            if (_local4 > 0){
                _local5 = Math.floor((((_local3 + _local4) - 1) / _local4));
            } else {
                _local4 = Math.floor((((_local3 + _local5) - 1) / _local5));
            };
            var _local6:int = this.tileWidth;
            var _local7:int = this.tileHeight;
            return (new IntDimension((((_local2.left + _local2.right) + (_local5 * _local6)) + ((_local5 - 1) * this.hgap)), (((_local2.top + _local2.bottom) + (_local4 * _local7)) + ((_local4 - 1) * this.vgap))));
        }
        public function getViewSize(_arg1:GridCellHolder):IntDimension{
            if ((((this.cols == 0)) && ((this.rows == 0)))){
                throw (new Error("rows and cols cannot both be zero"));
            };
            var _local2:Insets = _arg1.getInsets();
            var _local3:int = _arg1.getComponentCount();
            var _local4:int = this.rows;
            var _local5:int = this.cols;
            var _local6:GridList = _arg1.getList();
            var _local7:IntDimension = _local6.getExtentSize();
            if (((_local6.isTracksWidth()) || (_local6.isTracksHeight()))){
                if (_local6.isTracksHeight()){
                    _local4 = Math.floor(((_local7.height + this.vgap) / (this.tileHeight + this.vgap)));
                    _local5 = Math.floor((((_local3 + _local4) - 1) / _local4));
                } else {
                    _local5 = Math.floor(((_local7.width + this.hgap) / (this.tileWidth + this.hgap)));
                    _local4 = Math.floor((((_local3 + _local5) - 1) / _local5));
                };
            } else {
                if (_local4 > 0){
                    _local5 = Math.floor((((_local3 + _local4) - 1) / _local4));
                } else {
                    _local4 = Math.floor((((_local3 + _local5) - 1) / _local5));
                };
            };
            var _local8:int = this.tileWidth;
            var _local9:int = this.tileHeight;
            return (new IntDimension((((_local2.left + _local2.right) + (_local5 * _local8)) + ((_local5 - 1) * this.hgap)), (((_local2.top + _local2.bottom) + (_local4 * _local9)) + ((_local4 - 1) * this.vgap))));
        }
        override public function minimumLayoutSize(_arg1:Container):IntDimension{
            return (_arg1.getInsets().getOutsideSize());
        }
        override public function maximumLayoutSize(_arg1:Container):IntDimension{
            return (new IntDimension(1000000, 1000000));
        }
        override public function layoutContainer(_arg1:Container):void{
            var _local13:int;
            var _local14:int;
            if ((((this.cols == 0)) && ((this.rows == 0)))){
                throw (new Error("rows and cols cannot both be zero"));
            };
            var _local2:Insets = _arg1.getInsets();
            var _local3:int = _arg1.getComponentCount();
            var _local4:int = this.rows;
            var _local5:int = this.cols;
            if (_local3 == 0){
                return;
            };
            var _local6:IntRectangle = _local2.getInsideBounds(_arg1.getSize().getBounds());
            var _local7:GridList = GridCellHolder(_arg1).getList();
            if (((_local7.isTracksWidth()) || (_local7.isTracksHeight()))){
                if (_local7.isTracksHeight()){
                    _local4 = Math.floor(((_local6.height + this.vgap) / (this.tileHeight + this.vgap)));
                    _local5 = Math.floor((((_local3 + _local4) - 1) / _local4));
                } else {
                    _local5 = Math.floor(((_local6.width + this.hgap) / (this.tileWidth + this.hgap)));
                    _local4 = Math.floor((((_local3 + _local5) - 1) / _local5));
                };
            } else {
                if (_local4 > 0){
                    _local5 = Math.floor((((_local3 + _local4) - 1) / _local4));
                } else {
                    _local4 = Math.floor((((_local3 + _local5) - 1) / _local5));
                };
            };
            var _local8:int = this.getTileWidth();
            var _local9:int = this.getTileHeight();
            var _local10:int = _local2.left;
            var _local11:int = _local2.top;
            var _local12:int;
            while (_local12 < _local4) {
                _local10 = _local2.left;
                _local13 = 0;
                while (_local13 < _local5) {
                    _local14 = ((_local12 * _local5) + _local13);
                    if (_local14 < _local3){
                        _arg1.getComponent(_local14).setBounds(new IntRectangle(_local10, _local11, _local8, _local9));
                        _local7.getCellByIndex(_local14).setGridListCellStatus(_local7, _local7.isSelectedIndex(_local14), _local14);
                    };
                    _local10 = (_local10 + (_local8 + this.hgap));
                    _local13++;
                };
                _local11 = (_local11 + (_local9 + this.vgap));
                _local12++;
            };
        }

    }
}//package org.aswing.ext 
